package com.example.csdn.service.impl;

import com.example.csdn.DTO.AddCategoryDTO;
import com.example.csdn.DTO.UpdateCategoryDTO;
import com.example.csdn.mapper.CategoryMapper;
import com.example.csdn.pojo.Category;
import com.example.csdn.service.CategoryService;
import com.example.csdn.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public List<Category> AllCategory() {
        return categoryMapper.AllCategory();
    }

    @Override
    public Category findById(Integer id) {
        return categoryMapper.findById(id);
    }

    @Override
    public void add(AddCategoryDTO addCategoryDTO) {
        categoryMapper.add(addCategoryDTO);
    }

    @Override
    public void update(UpdateCategoryDTO updateCategoryDTO) {
        Category category = new Category();
        category.setCategoryName(updateCategoryDTO.getCategoryName());
        category.setCategoryDes(updateCategoryDTO.getCategoryDes());
        category.setId(updateCategoryDTO.getId());
        categoryMapper.update(category);
    }

    @Override
    public void delete(Integer id) {
        categoryMapper.delete(id);
    }
}
